from pathlib import Path
from pydantic import RedisDsn, AmqpDsn, PostgresDsn
from pydantic_settings import BaseSettings


class Settings(BaseSettings):
    """
    后端服务的配置
    """

    # 基础配置
    PROJECT_NAME: str = "checkProject"
    PROJECT_VERSION: str = "v1.0.0"
    DEBUG: bool = True
    BASE_DIR: Path = Path(__file__).resolve().parent.parent.parent
    API_V1_STR: str = "/api"


    # 数据库配置
    # ---------- sqlite ----------------
    SQLITE_URL: str = f"sqlite:///{BASE_DIR}" + "/" + "checkproject.db"
    USE_SQLITE: bool = True
    # ---------- sqlite ---------------

    # ---------- mysql ----------------
    #MYSQL_URl: str = "mysql://root:1990%12%02%lxc@127.0.0.1:3306/checkproject"
    MYSQL_URl: str = "mysql://root:1990%2512%2502%25lxc@127.0.0.1:3306/checkproject"
    USE_MYSQL: bool = False
    # ---------- mysql ----------------

    # ---------- postgresql -----------
    POSTGRES_URL: PostgresDsn = "postgresql://user:password@localhost:5432/checkProject"
    USE_POSTGRESQL: bool = False
    # ---------- postgresql -----------

    # MongoDB配置
    MONGODB_URL: str = "mongodb://localhost:27017"
    MONGODB_NAME: str = "checkProject"

    # Redis配置
    REDIS_URL: RedisDsn = "redis://localhost:6379/0"
    REDIS_EXPIRE: int = 3600

    # MinIO配置
    MINIO_ENDPOINT: str = "localhost:9000"
    MINIO_ACCESS_KEY: str = "minioadmin"
    MINIO_SECRET_KEY: str = "minioadmin"
    MINIO_SECURE: bool = False
    MINIO_BUCKET_NAME: str = "checkProject"

    # RabbitMQ配置
    RABBITMQ_URL: AmqpDsn = "amqp://guest:guest@localhost:5672/"

    # JWT配置
    JWT_SECRET_KEY: str = "checkProject2025"
    JWT_ALGORITHM: str = "HS256"
    JWT_ACCESS_TOKEN_EXPIRE_MINUTES: int = 120
    RSA_ENCRYPTION_ENABLED: bool = False

    # 应用配置
    ENABLED_APPS: list = [
        "auth",
        "users",
        "permissions",
        "menus",
        "logs"
    ]

    class Config:
        env_file = ".env"


settings = Settings()

if __name__ == "__main__":
    settings = Settings()
    print(settings.SQLITE_URL)
